const http = require('http');
const ejs =  require('ejs');

const server = http.createServer((req,res)=>{
    let rootPath = './NodeJS进阶';
    let pathname =  req.url;
    if (pathname === '/') {
        pathname = '/index.html'; /*默认加载的首页*/
    }
    if (pathname !== '/favicon.ico') { /*过滤请求favicon.ico*/
        ejs.renderFile(`${rootPath}/view/1.ejs`,(err,data)=>{
            if(err){
                console.log(err);
            }
            res.end(data);
        });
    }
    let arr = [];
    req.on('data',data => {
        arr.push(data);
    });
    req.on('end',()=>{
        console.log(arr.toString());
        console.log(req.headers['content-type']);
        
    });
});

server.listen(8012);